/*
 * helperfuncs.h
 * CS 3251 Programming Assignment #2
 * Dustin Shiflett
 */ 

#ifndef __HELPERFUNCS__
#define __HELPERFUNCS__

/* print functions for debug mode only */
#define dprint(x) if (debug) { printf(x); fflush(stdout); }
#define daprint(x,a) if (debug) { printf(x, a); fflush(stdout); }

/* error or non-debug printing */
#define printError(x) printf(x); fflush(stdout);


#define MAX_WINDOW_SIZE     32768 /*Max buffer size to expect (in bytes)*/
#define MAX_BUFFER_SIZE     65536 /*to be safe*/
#define MIN_WINDOW_SIZE     1024  /*Min buffer size to expect (in bytes)*/
#define MAXTRIES   20  /*# of times to retransmit if we don't get an ACK*/
#define MAX_ALARM_TIME  20
#define PROGID  901841089
#define SRTTCONSTANT    .125    /* 0 < a < 1; .125 = 1 / 8 */


/*packet and header structures*/
typedef struct {
    unsigned int progID, seqNum, maxPacketSize, windowSize;
    char fileName[256];
} initPacket;

typedef struct {
    unsigned int progID, seqNum;
    long fileSize;
} initReply;


typedef struct {
    unsigned int progID, nextSeqNumExpected;
} ackPacket;

typedef struct {
    unsigned int progID, seqNum, dataSize;
} dataHeader;

void closeSocket(int sockID);

int calcRTO(int origRTO, int RTT);
/*
origRTO: Smoothed Round Trip Time is origRTO / 2
RTT: Round Trip Time from the transmission of last packet until receiving the ACK for that packet
Returns the new Retransmission TimeOut
*/

long fileExists(char* fileName);
/*Returns the file size if exists, -1 otherwise*/

#endif
